﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.FreeIndexList
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Collections.Generic;

namespace Microsoft.InfoCards
{
  internal class FreeIndexList
  {
    private Dictionary<int, int> m_list;

    public FreeIndexList(int size)
    {
      if (size <= 0)
        throw InfoCardTrace.ThrowHelperError((Exception) new ArgumentOutOfRangeException(nameof (size), (object) size, SR.GetString("StoreFreeListSizeOutOfRange")));
      this.m_list = new Dictionary<int, int>(size);
    }

    public bool Contains(int value)
    {
      if (value <= 0)
        throw InfoCardTrace.ThrowHelperError((Exception) new ArgumentOutOfRangeException(nameof (value), (object) value, SR.GetString("StoreFreeListValueOutOfRange")));
      return this.m_list.ContainsKey(value);
    }

    public void Put(int value)
    {
      if (value <= 0)
        throw InfoCardTrace.ThrowHelperError((Exception) new ArgumentOutOfRangeException(nameof (value), (object) value, SR.GetString("StoreFreeListValueOutOfRange")));
      this.m_list.Add(value, value);
    }

    public int GetNext()
    {
      int key = -1;
      if (this.m_list.Count > 0)
      {
        using (IEnumerator<int> enumerator = (IEnumerator<int>) this.m_list.Keys.GetEnumerator())
        {
          enumerator.MoveNext();
          key = enumerator.Current;
        }
        this.m_list.Remove(key);
      }
      return key;
    }
  }
}
